package cn.redragon.soa.common.brand;

import java.util.Collections;
import java.util.Set;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.GenericConverter;

public class BrandConverter implements GenericConverter {

    @Override
    public Set<ConvertiblePair> getConvertibleTypes() {
        final ConvertiblePair[] pairs = new ConvertiblePair[]{
            new ConvertiblePair(String.class, Brand.class)
        };
        return Collections.unmodifiableSet(Set.of(pairs));
    }

    @Override
    public Object convert(final Object source, final TypeDescriptor sourceType, final TypeDescriptor targetType) {
        return Brand.valueOf(((String) source).toUpperCase());
    }
}